home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 76.8 KB | 2,616 lines | [TEXT/MPS ] |
- /*
- File: Shapes.cpp
-
- Contains: Shape Classes Implementation
-
- Written by: Dave Stafford
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- DrawEditor Includes --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- #ifndef _SHAPES_
- #include "Shapes.h"
- #endif
-
- #ifndef _FRAMEPROXY_
- #include "FrameProxy.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _LINK_
- #include "Link.h"
- #endif
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFacetIterator_xh
- #include <FacetItr.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h" // allow access to our library's resource fork
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h" // ODDisposePtr
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- // -- Toolbox Includes --
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- /*----------------------------------------------------------------------------------------
- Notes:
-
- • MovedFirst, MovedForward, MovedLast, MovedBackWard, are notifications that
- the given actions have occured, they should not be called to effect the change their
- names imply.
- • Added RemovedShape & RestoredShape. These are essentially for the proxy derivatives of shape.
- Removed & Restore shape should be called by commands that do this. The commands should tell
- the part to add/remove the shape ( not tell the shape to add itself to the part, like OPFDraw )
- Then, the part should notify the shape that the action has occured so it can adjust itself
- accordingly.
- ----------------------------------------------------------------------------------------*/
-
-
- // **************************** Need to improve Handling of Failure **********************
-
- //=============================================================================
- // class CShape
- //=============================================================================
-
- //------------------------------------------------------------------------------
- // CShape::CShape
- //------------------------------------------------------------------------------
-
- CShape::CShape(ODSShort numberOfHandles, ODSShort shapeType)
- {
- fRect = gGlobals->fZeroRect;
- fShapeType = shapeType;
- fNumberOfHandles = numberOfHandles;
- fSelected = kODFalse;
- fPromisedToClipboard = kODFalse;
-
- fColor = (*gGlobals->fBlackColor);
- fCanDrawColor = kODTrue;
- fShown = kODTrue;
-
- fPublishLinks = new COrderedList; //(MH)
- fSubscribeLink = kODNULL;
-
- fExternalizationIndex = 0;
-
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::~CShape
- //------------------------------------------------------------------------------
-
- CShape::~CShape()
- {
- if (fPublishLinks)
- delete fPublishLinks;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::IsPromisedToClipboard
- //------------------------------------------------------------------------------
-
- ODBoolean CShape::IsPromisedToClipboard() const
- {
- return fPromisedToClipboard;
- }
-
- //------------------------------------------------------------------------------
- // CShape::SetPromisedToClipboard
- //------------------------------------------------------------------------------
-
- void CShape::SetPromisedToClipboard(ODBoolean promised)
- {
- fPromisedToClipboard = promised;
- }
-
- //------------------------------------------------------------------------------
- // CShape::GetShapeType
- //------------------------------------------------------------------------------
-
- ODSShort CShape::GetShapeType() const
- {
- return fShapeType;
- }
-
- //------------------------------------------------------------------------------
- // CShape::SetCanDrawColor
- //------------------------------------------------------------------------------
-
- void CShape::SetCanDrawColor(ODBoolean toggle)
- {
- fCanDrawColor = toggle;
- }
-
- //------------------------------------------------------------------------------
- // CShape::GetCanDrawColor
- //------------------------------------------------------------------------------
-
- ODBoolean CShape::GetCanDrawColor()
- {
- return fCanDrawColor;
- }
-
- //------------------------------------------------------------------------------
- // CShape::SetColor
- //------------------------------------------------------------------------------
-
- void CShape::SetColor(const CRGBColor& color)
- {
- fColor = color;
- }
-
- //------------------------------------------------------------------------------
- // CShape::GetColor
- //------------------------------------------------------------------------------
-
- CRGBColor* CShape::GetColor()
- {
- return &fColor;
- }
-
- //------------------------------------------------------------------------------
- // CRectangleShape::Show
- //------------------------------------------------------------------------------
- void CShape::Show(Environment* ev, ODBoolean show)
- {
- fShown = show;
- }
-
- //------------------------------------------------------------------------------
- // CRectangleShape::IsShown
- //------------------------------------------------------------------------------
- ODBoolean CShape::IsShown()
- {
- return fShown;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::Draw
- //------------------------------------------------------------------------------
-
- void CShape::DrawShape(Environment* ev, ODFacet* facet)
- {
- if (IsSelected()&&IsShown())
- DrawHandles();
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetUpdateShape
- //------------------------------------------------------------------------------
-
- void CShape::GetUpdateShape(Environment* ev, ODShape* updateShape) const
- {
- ODRect bounds(fRect);
- bounds.left -= fl(2.5);
- bounds.top -= fl(2.5);
- bounds.right += fl(2.5);
- bounds.bottom += fl(2.5);
- updateShape->SetRectangle(ev, &bounds);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetUpdateBox
- //------------------------------------------------------------------------------
-
- void CShape::GetUpdateBox(Environment* ev, ODRect* updateBox) const
- {
- ODRect bounds(fRect);
- updateBox->left -= fl(2.5);
- updateBox->top -= fl(2.5);
- updateBox->right += fl(2.5);
- updateBox->bottom += fl(2.5);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetBoundingRegion
- //------------------------------------------------------------------------------
-
- ODRgnHandle CShape::GetBoundingRegion() const
- {
- ODRgnHandle tRegion = NewRgn();
- THROW_IF_NULL(tRegion);
-
- RectRgn(tRegion, &fRect);
-
- return tRegion;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetBoundingBox
- //------------------------------------------------------------------------------
-
- void CShape::GetBoundingBox(Rect* bounds) const
- {
- *bounds = fRect;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetBoundingBox
- //------------------------------------------------------------------------------
-
- void CShape::GetBoundingBox(ODRect* bounds) const
- {
- *bounds = fRect;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CShape::SetBoundingBox(Environment* ev, const Rect& bounds)
- {
- fRect = bounds;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CShape::SetBoundingBox(Environment* ev, ODShape* bounds)
- {
- THROW_IF_NULL(bounds);
-
- ODRgnHandle tRegion = bounds->GetQDRegion(ev);
- Rect tRect = (*tRegion)->rgnBBox;
-
- this->SetBoundingBox(ev, tRect);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CShape::SetBoundingBox(Environment* ev, const Point& anchorPoint, const Point& currentPoint)
- {
- if (anchorPoint.h < currentPoint.v)
- {
- fRect.left = anchorPoint.h;
- fRect.right = currentPoint.h;
- }
- else
- {
- fRect.left = currentPoint.h;
- fRect.right = anchorPoint.h;
- }
-
- if (anchorPoint.v < currentPoint.v)
- {
- fRect.top = anchorPoint.v;
- fRect.bottom = currentPoint.v;
- }
- else
- {
- fRect.top = currentPoint.v;
- fRect.bottom = anchorPoint.v;
- }
- }
-
- //------------------------------------------------------------------------------
- // CShape::ContainsProxyForFrame
- //
- // This method should return kODTrue if the given frame is embedded within this
- // item of content.
- //------------------------------------------------------------------------------
-
- ODBoolean CShape::ContainsProxyForFrame(Environment* ev, ODFrame* frame)
- {
- // CShapes cannot represent embedded content, so alway return kODFalse
- return kODFalse;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SetInLimbo
- //
- //------------------------------------------------------------------------------
-
- void CShape::SetInLimbo(Environment* ev, ODBoolean isInLimbo)
- {
- // Limbo is an embedded frame issue, do nothing here.
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::OffsetShape
- //------------------------------------------------------------------------------
-
- void CShape::OffsetShape(Environment* ev, ODCoordinate xDelta, ODCoordinate yDelta)
- {
- ::OffsetRect( &fRect, FixedToInt(xDelta), FixedToInt(yDelta) );
- }
-
- //------------------------------------------------------------------------------
- // CShape::GetHandleCenter
- //------------------------------------------------------------------------------
-
- void CShape::GetHandleCenter(short whichHandle, Point* center) const
- {
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- center->h = fRect.left;
- center->v = fRect.top;
- break;
- case kInTopRightCorner:
- center->h = fRect.right;
- center->v = fRect.top;
- break;
- case kInBottomLeftCorner:
- center->h = fRect.left;
- center->v = fRect.bottom;
- break;
- case kInBottomRightCorner:
- center->h = fRect.right;
- center->v = fRect.bottom;
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // CShape::CalcHandle
- //------------------------------------------------------------------------------
-
- void CShape::CalcHandle(short whichHandle, Rect* bounds) const
- {
- Point pt;
- GetHandleCenter(whichHandle, &pt);
-
- bounds->top = pt.v - 2;
- bounds->left = pt.h - 2;
- bounds->bottom = pt.v + 2;
- bounds->right = pt.h + 2;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::DrawHandles
- //------------------------------------------------------------------------------
-
- void CShape::DrawHandles()
- {
- Rect handleRect;
-
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- // Set the color
- RGBForeColor((RGBColor*)&gGlobals->fBlackColor);
-
- for (short i=1; i<=fNumberOfHandles; i++)
- {
- CalcHandle(i, &handleRect);
- PaintRect(&handleRect);
- }
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
-
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::ShapeInRectangle
- //------------------------------------------------------------------------------
-
- ODBoolean CShape::ShapeInRectangle(const Rect& rect) const
- {
- Rect bounds;
- GetBoundingBox(&bounds);
-
- Rect intersection;
- SectRect(&bounds, &rect, &intersection);
-
- // If the Intersection is equal to the bounds
- // then we are fully contained by the given rectangle.
- return EqualRect(&bounds,&intersection);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SelectShape
- //------------------------------------------------------------------------------
-
- void CShape::SelectShape(Environment* ev, ODBoolean state)
- {
- ASSERT(fSelected != state, kODErrAssertionFailed);
-
- fSelected = state;
-
- COrderedList* pubLinks;
-
- if (fSubscribeLink)
- {
- fSubscribeLink->ShapeSelected(state);
- pubLinks = fSubscribeLink->GetPublishLinks();
- }
- else
- {
- pubLinks = fPublishLinks;
- }
-
- COrdListIterator linkIte(pubLinks);
- for (CPublishLink* pLink = (CPublishLink*)linkIte.First(); linkIte.IsNotComplete(); pLink = (CPublishLink*)linkIte.Next())
- {
- pLink->ShapeSelected(state);
- }
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::WhichHandle
- //------------------------------------------------------------------------------
-
- ODSShort CShape::WhichHandle(const Point& mouse) const
- {
- Rect handleRect;
- for (short i=1; i<=fNumberOfHandles; i++)
- {
- CalcHandle( i, &handleRect );
- if (::PtInRect(mouse, &handleRect))
- return i;
- }
-
- return 0;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::GetDragRect
- //------------------------------------------------------------------------------
-
- void CShape::GetDragRect(Rect* dragRect) const
- {
- GetBoundingBox(dragRect);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::CreateDragShape
- // Be sure to release the shape returned from this call
- //------------------------------------------------------------------------------
-
- ODShape* CShape::CreateDragShape(Environment *ev, ODFacet* facet)
- {
- ODRect bounds(fRect);
-
- ODShape* dragRgn = facet->CreateShape(ev);
- dragRgn->SetRectangle(ev, &bounds);
-
- bounds.Inset(ff(1), ff(1));
-
- ODShape* donutHole = facet->CreateShape(ev);
- donutHole->SetRectangle(ev, &bounds);
-
- dragRgn->Subtract(ev, donutHole);
- ODReleaseObject(ev, donutHole);
-
- return dragRgn;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::InvalidateHandles
- // Be sure to release the shape returned from this call
- //------------------------------------------------------------------------------
-
- void CShape::InvalidateHandles(Environment *ev, ODFrame* frame)
- {
- ODRect bounds(fRect);
-
- // Invalidate all the shape handles
- Rect handleRect;
- ODShape* tShape = frame->CreateShape(ev);
-
- for (short i=1; i<=fNumberOfHandles; i++)
- {
- CalcHandle(i, &handleRect);
- ODRect handle(handleRect);
- tShape->SetRectangle(ev, &handle);
-
- frame->Invalidate(ev, tShape, kODNULL);
- }
-
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::ResizeFeedback
- //------------------------------------------------------------------------------
-
- void CShape::ResizeFeedback(ODFacet* facet, short whichHandle, Point& mouseLoc, ODBoolean draw)
- {
- Rect srcRect, dstRect;
- GetResizeRect(whichHandle, mouseLoc, &srcRect, &dstRect);
- SortRect(&dstRect);
- OutlineShape(facet, dstRect, draw);
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::Resize
- //------------------------------------------------------------------------------
-
- void CShape::Resize(Environment *ev, Rect& baseRect, Rect& resizeRect)
- {
- MapRect(baseRect, resizeRect, &fRect);
- }
- //------------------------------------------------------------------------------
- // CShape::GetResizeRect
- //------------------------------------------------------------------------------
- void CShape::GetResizeRect(ODSShort whichHandle, Point& mouseLoc, Rect* srcRect, Rect* dstRect)
- {
- *srcRect = fRect;
- *dstRect = *srcRect;
-
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- dstRect->left = mouseLoc.h;
- dstRect->top = mouseLoc.v;
- break;
- case kInTopRightCorner:
- dstRect->right = mouseLoc.h;
- dstRect->top = mouseLoc.v;
- break;
- case kInBottomLeftCorner:
- dstRect->left = mouseLoc.h;
- dstRect->bottom = mouseLoc.v;
- break;
- case kInBottomRightCorner:
- dstRect->right = mouseLoc.h;
- dstRect->bottom = mouseLoc.v;
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Activate
- //
- // Description:
- // Nothing is done here, Embedding shapes will override.
- //------------------------------------------------------------------------------
-
- void CShape::Activate(Environment* ev, ODBoolean activating, ODFrame* frame)
- {
-
- }
-
- //------------------------------------------------------------------------------
- // CShape::MoveAfter
- // This method is called to move 'this' shape after the given one.
- // Nothing is done here, Embedding shapes will override.
- //------------------------------------------------------------------------------
- void CShape::MoveAfter(Environment* ev, CShape* shape)
- {
-
- }
-
- //------------------------------------------------------------------------------
- // CShape::MoveBefore
- // This method is called to move 'this' shape before the given one.
- // Nothing is done here, Embedding shapes will override.
- //------------------------------------------------------------------------------
- void CShape::MoveBefore(Environment* ev, CShape* shape)
- {
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::IsFrozen
- // This will probably be only overridden by the proxy derivatives of shape
- // Nothing is done here, Embedding shapes will override.
- //------------------------------------------------------------------------------
-
- ODBoolean CShape::IsFrozen() const
- {
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // CShape::SetFrozen
- // This method is called after the action has completed.
- // This will probably be only overridden by the Embedding derivatives of shape
- //------------------------------------------------------------------------------
- ODBoolean CShape::SetFrozen(ODBoolean state)
- {
- UNUSED(state);
- return kODFalse; // Means I don't care
- }
-
- //------------------------------------------------------------------------------
- // CShape::Added
- // This method is called after the action has completed.
- // This will probably be only overridden by the Embedding derivatives of shape.
- //------------------------------------------------------------------------------
- void CShape::Added(Environment *ev)
- {
- if(fSubscribeLink)
- fSubscribeLink->AddShape(this);
- else
- {
- COrdListIterator ite(fPublishLinks);
- for (CPublishLink* plink = (CPublishLink*)ite.First(); ite.IsNotComplete(); plink = (CPublishLink*)ite.Next())
- plink->AddShape(this);
- }
-
- }
-
- //------------------------------------------------------------------------------
- // CShape::Removed
- // This method is called after the action has completed.
- // This will probably be only overridden by the proxy derivatives of shape.
- //------------------------------------------------------------------------------
- void CShape::Removed(Environment* ev, ODBoolean commit)
- {
- if(fSubscribeLink)
- fSubscribeLink->RemoveShape(this);
- else
- {
- COrdListIterator ite(fPublishLinks);
- for (CPublishLink* plink = (CPublishLink*)ite.First(); ite.IsNotComplete(); plink = (CPublishLink*)ite.Next())
- plink->RemoveShape(this);
-
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CShape::Open
- //
- // This method is called by the part when the user has selected "Open" for a selection.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::Open(Environment *ev, ODFrame* container)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CShape::DisplayFrameConnected
- //
- // This method is called by the part when a display frame is added for the first time.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::DisplayFrameConnected(Environment *ev, ODFrame* frame)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CShape::DisplayFrameAdded
- //
- // This method is called by the part when a display frame is added for the first time.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::DisplayFrameAdded(Environment *ev, ODFrame* frame)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CShape::DisplayFrameRemoved
- //
- // This method is called by the part when a display frame is removed.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::DisplayFrameRemoved(Environment *ev, ODFrame* frame)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CShape::Dragging
- //
- // This method is called by the part when a the user is dragging this shape.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::Dragging(Environment *ev, ODBoolean dragging)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CShape::FacetAdded
- //
- // This method is called by the part when a new containing facet is added.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::FacetAdded(Environment *ev, ODFacet* facet)
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::DisplayFrameClosed
- //
- // This method is called by the part when a display frame is removed.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::DisplayFrameClosed(Environment *ev, ODFrame* frame)
- {
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CShape::FacetRemoved
- //
- // This method is called by the part when a containing facet is removed.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CShape::FacetRemoved(Environment *ev, ODFacet* facet)
- {
- }
-
- //------------------------------------------------------------------------------
- // CShape::Read
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is the beginning of a shape.
- //------------------------------------------------------------------------------
- void CShape::Read(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo)
- {
- UNUSED(cloneInfo);
-
- TRY
- // Get the rectangle
- StorageUnitViewGetValue(view, ev, sizeof(Rect), &fRect);
-
- // Get the shape type
- StorageUnitViewGetValue(view, ev, sizeof(ODSShort), &fShapeType);
-
- // Get the number of handles
- StorageUnitViewGetValue(view, ev, sizeof(ODSShort), &fNumberOfHandles);
-
- // Get the shape color
- StorageUnitViewGetValue(view, ev, sizeof(CRGBColor), &fColor);
-
- ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::Read
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is the beginning of a shape.
- //------------------------------------------------------------------------------
- void CShape::Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo)
- {
- UNUSED(cloneInfo);
-
- TRY
- // Get the rectangle
- StorageUnitGetValue(storage, ev, sizeof(Rect), &fRect);
-
- // Get the shape type
- StorageUnitGetValue(storage, ev, sizeof(ODSShort), &fShapeType);
-
- // Get the number of handles
- StorageUnitGetValue(storage, ev, sizeof(ODSShort), &fNumberOfHandles);
-
- // Get the shape color
- StorageUnitGetValue(storage, ev, sizeof(CRGBColor), &fColor);
-
- ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::Write
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is a good place to write out a shape.
- //------------------------------------------------------------------------------
- void CShape::Write(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo)
- {
- UNUSED(cloneInfo);
-
- TRY
- // Write the rectangle
- StorageUnitViewSetValue(view, ev, sizeof(Rect), &fRect);
-
- // Write the shape type
- StorageUnitViewSetValue(view, ev, sizeof(ODSShort), &fShapeType);
-
- // Write the number of handles
- StorageUnitViewSetValue(view, ev, sizeof(ODSShort), &fNumberOfHandles);
-
- // Write the shape color
- StorageUnitViewSetValue(view, ev, sizeof(CRGBColor), &fColor);
-
- ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::Write
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is a good place to write out a shape.
- //------------------------------------------------------------------------------
- void CShape::Write(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo)
- {
- UNUSED(cloneInfo);
-
- TRY
- // Write the rectangle
- StorageUnitSetValue(storage, ev, sizeof(Rect), &fRect);
-
- // Write the shape type
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &fShapeType);
-
- // Write the number of handles
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &fNumberOfHandles);
-
- // Write the shape color
- StorageUnitSetValue(storage, ev, sizeof(CRGBColor), &fColor);
-
- ENDTRY
- }
-
- void CShape::Publish(Environment* ev, CPublishLink *publishLink)
- {
- // If its subscribed, nobody should be publishing it.
- ASSERT(!fSubscribeLink, kODErrAssertionFailed);
-
- fPublishLinks->AddLast(publishLink);
- }
-
-
- ODBoolean CShape::IsPublished()
- {
- return (fPublishLinks->Count() != 0);
- }
-
-
- #pragma segment Main
- void CShape::Subscribe(Environment* ev, CSubscribeLink* link)
- {
- ASSERT(fSubscribeLink == kODNULL, kODErrAssertionFailed);
-
- fPublishLinks->RemoveAllLinks();
-
- fSubscribeLink= link;
- }
-
- #pragma segment Main
- void CShape::SetExternalizationIndex(ODUShort index)
- {
- fExternalizationIndex = index;
- }
-
-
- #pragma segment Main
- ODUShort CShape::GetExternalizationIndex()
- {
- return fExternalizationIndex;
- }
-
-
- #pragma segment Main
- void CShape::Unpublish(Environment* ev, CPublishLink* publishLink)
- {
- // $$$$$ Test could probably be replaced by an assertion.
- if (!fSubscribeLink)
- fPublishLinks->Remove(publishLink);
- }
-
-
- #pragma segment Main
- void CShape::Unsubscribe(Environment* ev)
- {
- ASSERT(fSubscribeLink, kODErrAssertionFailed);
- ASSERT(fPublishLinks->Count() == 0, kODErrAssertionFailed);
-
- COrdListIterator iter(fSubscribeLink->GetPublishLinks());
- for (CPublishLink* pLink = (CPublishLink*)iter.First(); iter.IsNotComplete(); pLink = (CPublishLink*)iter.Next())
- {
- fPublishLinks->AddLast(pLink);
- }
-
- fSubscribeLink = kODNULL;
- }
-
-
-
- //=============================================================================
- // class CRectangleShape
- //=============================================================================
-
- //------------------------------------------------------------------------------
- // Method: CRectangleShape Constructor
- //
- // Description: We allow the caller to pass in a shape type here so that
- // classes can derive from this one and have their own type.
- //
- //------------------------------------------------------------------------------
- CRectangleShape::CRectangleShape(ODSShort shapeType) :
- CShape(kNumberOfHandles, shapeType)
- {
- }
-
- //------------------------------------------------------------------------------
- // CRectangleShape::~CRectangleShape
- //------------------------------------------------------------------------------
- CRectangleShape::~CRectangleShape()
- {
- }
-
-
-
- //------------------------------------------------------------------------------
- // CRectangleShape::CreateDragShape
- // Be sure to release the shape returned from this call
- //------------------------------------------------------------------------------
- ODShape* CRectangleShape::CreateDragShape(Environment *ev, ODFacet* facet)
- {
- ODRect bounds(fRect);
-
- ODShape* dragRgn = facet->CreateShape(ev);
- dragRgn->SetRectangle(ev, &bounds);
-
- bounds.Inset(ff(1), ff(1));
-
- ODShape* donutHole = facet->CreateShape(ev);
-
- donutHole->SetRectangle(ev, &bounds);
- dragRgn->Subtract(ev, donutHole);
- ODReleaseObject(ev, donutHole);
-
- return dragRgn;
- }
-
-
- //------------------------------------------------------------------------------
- // CRectangleShape::OutlineShape
- //------------------------------------------------------------------------------
- void CRectangleShape::OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw)
- {
- ::FrameRect(&rect);
- }
-
- //------------------------------------------------------------------------------
- // CRectangleShape::HitTest
- //------------------------------------------------------------------------------
- ODBoolean CRectangleShape::HitTest(Environment *ev, const Point& where) const
- {
- ODRect bounds(fRect);
- ODPoint mouse(where);
-
- return bounds.Contains(mouse);
- }
-
-
-
- //------------------------------------------------------------------------------
- // CRectangleShape::DrawShape
- //------------------------------------------------------------------------------
- void CRectangleShape::DrawShape(Environment* ev, ODFacet* facet)
- {
- CShape::DrawShape(ev, facet);
-
- if (this->IsShown())
- {
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- // Draw the color
- if (this->GetCanDrawColor())
- {
- ::RGBForeColor((RGBColor*)GetColor());
-
- // Paint the rectangle
- ::PaintRect(&fRect);
- }
-
- // Frame the rectangle
- RGBForeColor((RGBColor*)&gGlobals->fBlackColor);
- ::FrameRect(&fRect);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
- }
-
- }
-
- //=============================================================================
- // class COvalShape
- //=============================================================================
-
- //------------------------------------------------------------------------------
- // Method: COvalShape Constructor
- //
- //
- //------------------------------------------------------------------------------
- COvalShape::COvalShape() : CShape(kNumberOfHandles, kOvalShape)
- {
- }
-
- //------------------------------------------------------------------------------
- // COvalShape::~COvalShape
- //------------------------------------------------------------------------------
- COvalShape::~COvalShape()
- {
- }
-
- //------------------------------------------------------------------------------
- // COvalShape::GetBoundingRegion
- // Be sure to dispose of the region returned from this call
- //------------------------------------------------------------------------------
- ODRgnHandle COvalShape::GetBoundingRegion() const
- {
- ODRgnHandle ovalRgn = ::NewRgn();
- THROW_IF_NULL(ovalRgn);
-
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- // Frame the oval
- PenNormal();
-
- // Generate a QD region for the oval
- ::OpenRgn();
-
- ::FrameOval(&fRect);
- ::CloseRgn(ovalRgn);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
-
- return ovalRgn;
- }
-
- //------------------------------------------------------------------------------
- // COvalShape::CreateDragShape
- // Be sure to release the shape returned from this call
- //------------------------------------------------------------------------------
- ODShape* COvalShape::CreateDragShape(Environment *ev, ODFacet* facet)
- {
- ODRgnHandle ovalRgn = this->GetBoundingRegion();
-
- ODShape* dragRgn = facet->CreateShape(ev);
- dragRgn->SetQDRegion(ev, ovalRgn);
-
- return dragRgn;
- }
-
- //------------------------------------------------------------------------------
- // COvalShape::OutlineShape
- //------------------------------------------------------------------------------
- void COvalShape::OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw)
- {
- // Should draw the actual shape instead of just an outline
- ::FrameOval(&rect);
- }
-
- //------------------------------------------------------------------------------
- // COvalShape::HitTest
- //------------------------------------------------------------------------------
- ODBoolean COvalShape::HitTest(Environment *ev, const Point& where) const
- {
- ODBoolean result = kODFalse;
-
- // Generate a QD region for the oval
- RgnHandle ovalRgn = NewRgn();
- THROW_IF_NULL(ovalRgn);
-
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- OpenRgn();
- PenNormal();
- FrameOval(&fRect);
- CloseRgn(ovalRgn);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
-
- // Test the point against the region
- result = PtInRgn(where, ovalRgn);
-
- // Free the region
- DisposeRgn(ovalRgn);
-
- return result;
- }
-
-
-
- //------------------------------------------------------------------------------
- // COvalShape::DrawShape
- //------------------------------------------------------------------------------
- void COvalShape::DrawShape(Environment* ev, ODFacet* facet)
- {
- CShape::DrawShape(ev, facet);
-
- if (this->IsShown())
- {
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- RGBForeColor((RGBColor*)GetColor());
-
- // Paint the rectangle
- ::PaintOval(&fRect);
-
- // Frame the rectangle
- RGBForeColor((RGBColor*)&gGlobals->fBlackColor);
- ::FrameOval(&fRect);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
- }
- }
-
-
- //=============================================================================
- // class CPolygonShape
- //=============================================================================
-
- //------------------------------------------------------------------------------
- // Method: CPolygonShape Constructor
- //
- //
- //------------------------------------------------------------------------------
- CPolygonShape::CPolygonShape() : CShape(kNumberOfHandles, kPolygonShape)
- {
- fPolygon = kODNULL;
- fSides = 0;
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::~CPolygonShape
- //------------------------------------------------------------------------------
- CPolygonShape::~CPolygonShape()
- {
- KillPoly(fPolygon);
- }
-
- //------------------------------------------------------------------------------
- // CShape::Read
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is the beginning of a shape.
- //------------------------------------------------------------------------------
- void CPolygonShape::Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo)
- {
- CShape::Read(ev, storage, cloneInfo);
-
- this->SetPolygon(3);
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::SetPolygon
- // Assumes fRect is set by this time.
- //------------------------------------------------------------------------------
- void CPolygonShape::SetPolygon(ODSShort numSides)
- {
- fSides = numSides;
-
- // Initialize the polygon
- fPolygon = OpenPoly();
-
- ODSShort shapeWidth = fRect.right-fRect.left;
-
- // Test with triangle
- MoveTo(fRect.left + shapeWidth / 2,fRect.top);
- LineTo(fRect.right, fRect.bottom);
- LineTo(fRect.left, fRect.bottom);
- LineTo(fRect.left + shapeWidth / 2,fRect.top);
-
- // Terminate recording of the polygon
- ClosePoly();
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::GetBoundingRegion
- // Be sure to dispose of the region returned from this call
- //------------------------------------------------------------------------------
- ODRgnHandle CPolygonShape::GetBoundingRegion() const
- {
- ODRgnHandle PolygonRgn = ::NewRgn();
- THROW_IF_NULL(PolygonRgn);
-
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- // Generate a QD region for the Polygon
- ::OpenRgn();
- ::PenNormal();
- ::FramePoly(fPolygon);
- ::CloseRgn(PolygonRgn);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
-
- return PolygonRgn;
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::Resize
- //------------------------------------------------------------------------------
- void CPolygonShape::Resize(Environment *ev, Rect& baseRect, Rect& resizeRect)
- {
- CShape::Resize(ev, baseRect, resizeRect);
-
- this->SetPolygon(3);
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::CreateDragShape
- // Be sure to release the shape returned from this call
- //------------------------------------------------------------------------------
- ODShape* CPolygonShape::CreateDragShape(Environment *ev, ODFacet* facet)
- {
- ODRgnHandle PolygonRgn = this->GetBoundingRegion();
-
- ODShape* dragRgn = facet->CreateShape(ev);
- dragRgn->SetQDRegion(ev, PolygonRgn);
-
- return dragRgn;
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::OffsetShape
- //------------------------------------------------------------------------------
-
- void CPolygonShape::OffsetShape(Environment* ev, ODCoordinate xDelta, ODCoordinate yDelta)
- {
- // Call inherited
- CShape::OffsetShape(ev, xDelta, yDelta);
-
- ::OffsetPoly(fPolygon, FixedToInt(xDelta), FixedToInt(yDelta));
- }
-
-
- //------------------------------------------------------------------------------
- // CPolygonShape::OutlineShape
- //------------------------------------------------------------------------------
- void CPolygonShape::OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw)
- {
- // Should draw the actual shape instead of just an outline
- ::FramePoly(fPolygon);
- }
-
- //------------------------------------------------------------------------------
- // CPolygonShape::HitTest
- //------------------------------------------------------------------------------
- ODBoolean CPolygonShape::HitTest(Environment *ev, const Point& where) const
- {
- ODBoolean result = kODFalse;
-
- // Generate a QD region for the Polygon
- RgnHandle PolygonRgn = NewRgn();
- THROW_IF_NULL(PolygonRgn);
-
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- ::OpenRgn();
- ::PenNormal();
- ::FramePoly(fPolygon);
- ::CloseRgn(PolygonRgn);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
-
- // Test the point against the region
- result = PtInRgn(where, PolygonRgn);
-
- // Free the region
- DisposeRgn(PolygonRgn);
-
- return result;
- }
-
-
-
- //------------------------------------------------------------------------------
- // CPolygonShape::DrawShape
- //------------------------------------------------------------------------------
- void CPolygonShape::DrawShape(Environment* ev, ODFacet* facet)
- {
- CShape::DrawShape(ev, facet);
-
- if (this->IsShown())
- {
- // Save the Pen
- PenState tPen;
- RGBColor tColor;
- GetPenState(&tPen);
- GetForeColor(&tColor);
-
- RGBForeColor((RGBColor*)GetColor());
-
- // Paint the rectangle
- ::PaintPoly(fPolygon);
-
- // Frame the rectangle
- RGBForeColor((RGBColor*)&gGlobals->fBlackColor);
- ::FramePoly(fPolygon);
-
- // Restore state
- RGBForeColor(&tColor);
- SetPenState(&tPen);
- }
- }
-
-
- //=============================================================================
- // class CEmbeddingShape
- //=============================================================================
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::CEmbeddingShape
- //------------------------------------------------------------------------------
- CEmbeddingShape::CEmbeddingShape(DrawEditor* drawEditor) :
- CRectangleShape(kEmbeddingShape)
- {
- fDrawEditor = drawEditor;
- fFrozen = kODFalse;
- fFrameProxies = kODNULL;
-
- this->SetCanDrawColor(kODFalse);
-
- // Go ahead and allocate the list here
- fFrameProxies = new COrderedList;
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::~CEmbeddingShape
- //------------------------------------------------------------------------------
- CEmbeddingShape::~CEmbeddingShape()
- {
- Environment* ev = somGetGlobalEnvironment();
-
- if (fFrameProxies)
- {
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // This code assumes that the shape has been removed before now.
- delete frameProxy;
- }
-
- delete fFrameProxies;
- fFrameProxies = kODNULL;
- }
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetBoundingBox(Environment* ev, const Rect& bounds)
- {
- CShape::SetBoundingBox(ev, bounds);
-
- // Update frame shapes for frames we are for which we are proxying
- this->SetProxyBounds(ev, fRect);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetBoundingBox(Environment* ev, ODShape* bounds)
- {
- CShape::SetBoundingBox(ev, bounds);
-
- // Update frame shapes for frames we are for which we are proxying
- this->SetProxyBounds(ev, fRect);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SetShapeRectangle
- //
- // Set the rectangle for the shape without adjusting the embedded frames bounds.
- // This is necessary in cases where OpenDoc is gonig to change the embedded frame
- // shape on us and we need to adjust the intrinsic shape's bounds without changing
- // the frame shape ( causing stack overflow ).
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetShapeRectangle(Environment* ev, ODShape* bounds)
- {
- // Change the bounds rect of the shape without affecting the embedded frame(s)
- ODRgnHandle tRegion = bounds->GetQDRegion(ev);
- Rect tRect = (*tRegion)->rgnBBox;
-
- fRect = tRect;
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SetBoundingBox
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetBoundingBox(Environment* ev, const Point& anchorPoint, const Point& currentPoint)
- {
- CShape::SetBoundingBox(ev, anchorPoint, currentPoint);
-
- // Update frame shapes for frames we are for which we are proxying
- this->SetProxyBounds(ev, fRect);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SetProxyBounds
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetProxyBounds(Environment* ev, const Rect& bounds)
- {
- ODRect tRect(bounds);
-
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- frameProxy->ResizeFrame(ev, tRect);
- }
- }
-
-
- //------------------------------------------------------------------------------
- // Method: AddFrameProxy
- //
- // Description:
- //
- //------------------------------------------------------------------------------
- void CEmbeddingShape::AddFrameProxy(CEmbeddedFrameProxy* frameProxy)
- {
- fFrameProxies->AddLast(frameProxy);
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::MoveAfter
- // This method is called to move 'this' shape after the given one.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::MoveAfter(Environment* ev, CShape* shape)
- {
- // If the given shape is not an embedding shape then
- // we have nothing to do
- if (shape->GetShapeType() != kEmbeddingShape)
- {
- return;
- }
-
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // Get the embedded frame for this shape
- ODFrame* embeddedFrame = frameProxy->GetFrame(ev);
-
- // Iterate over the facets for this frame
- ODFrameFacetIterator* facetIter = embeddedFrame->CreateFacetIterator(ev);
- for (ODFacet* embeddedFacet = facetIter->First(ev);
- facetIter->IsNotComplete(ev); embeddedFacet = facetIter->Next(ev))
- {
- // Get the facet for the given shape which shares our
- // containing facet
- ODFacet* containingFacet = embeddedFacet->GetContainingFacet(ev);
- ODFacet* shapeFacet = ((CEmbeddingShape*)shape)->GetEmbeddedFacet(ev, containingFacet);
- containingFacet->MoveBehind(ev, embeddedFacet, shapeFacet);
- }
-
- delete facetIter;
- }
-
- // Invalidate the shapes
- fDrawEditor->InvalidateShape(ev, this);
- fDrawEditor->InvalidateShape(ev, shape);
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::MoveBefore
- // This method is called to move 'this' shape before the given one.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::MoveBefore(Environment* ev, CShape* shape)
- {
- // If the given shape is not an embedding shape then
- // we have nothing to do
- if (shape->GetShapeType() != kEmbeddingShape)
- {
- return;
- }
-
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // Get the embedded frame for this shape
- ODFrame* embeddedFrame = frameProxy->GetFrame(ev);
-
- // Iterate over the facets for this frame
- ODFrameFacetIterator* facetIter = embeddedFrame->CreateFacetIterator(ev);
- for (ODFacet* embeddedFacet = facetIter->First(ev);
- facetIter->IsNotComplete(ev); embeddedFacet = facetIter->Next(ev))
- {
- // Get the facet for the given shape which shares our
- // containing facet
- ODFacet* containingFacet = embeddedFacet->GetContainingFacet(ev);
- ODFacet* shapeFacet = ((CEmbeddingShape*)shape)->GetEmbeddedFacet(ev, containingFacet);
- containingFacet->MoveBefore(ev, embeddedFacet, shapeFacet);
- }
-
- delete facetIter;
- }
-
- // Invalidate the shapes
- fDrawEditor->InvalidateShape(ev, this);
- fDrawEditor->InvalidateShape(ev, shape);
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::SelectShape
- //
- // Description:
- //
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SelectShape(Environment* ev, ODBoolean state)
- {
- CRectangleShape::SelectShape(ev, state);
-
- // Set the selected & hilighted flags of all facets of all our frame
- // proxies
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- TRY
- ODFrame* frame = frameProxy->GetFrame(ev);
- THROW_IF_NULL(frame);
-
- ODFrameFacetIterator* iter2 = frame->CreateFacetIterator(ev);
- for (ODFacet* facet = iter2->First(ev); iter2->IsNotComplete(ev); facet = iter2->Next(ev))
- {
- TempODWindow window = facet->GetFrame(ev)->AcquireWindow(ev);
- THROW_IF_NULL(window);
-
- ODBoolean active = window->IsActive(ev);
-
- ODHighlight highlight;
-
- if ( this->IsSelected() && active )
- highlight = kODFullHighlight;
- else if ( this->IsSelected() && !active )
- highlight = kODDimHighlight;
- else
- highlight = kODNoHighlight;
-
- facet->SetSelected(ev, state);
-
- ::ChangeFacetHighlight(ev, facet, highlight);
- }
-
- delete iter2;
-
- CATCH_ALL
- DebugStr("\pProblem selecting shape!");
- ENDTRY
- }
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::DrawShape
- //------------------------------------------------------------------------------
- void CEmbeddingShape::DrawShape(Environment* ev, ODFacet* facet)
- {
- if (this->IsShown())
- {
- // Draw the embedded part
- RgnHandle tRegion = NewRgn();
- THROW_IF_NULL(tRegion);
-
- // Temp Shape
- ODShape* tShape = facet->CreateShape(ev);
-
- // Get the clipping region & convert to ODShape
- ODShape* tClippingShape = facet->CreateShape(ev);
- GetClip(tRegion);
- tClippingShape->SetQDRegion(ev, tRegion); // SetQDRegion consumes the region
-
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // Getting the frame will also ensure that there is one ( a frame, that is )
- ODFrame* embeddedFrame = frameProxy->GetFrame(ev);
-
- ODFrameFacetIterator* iter = embeddedFrame->CreateFacetIterator(ev);
- for (ODFacet* embeddedFacet = iter->First(ev); iter->IsNotComplete(ev); embeddedFacet = iter->Next(ev))
- {
- // Set up the clip for the embedded facet
- // DCS $$$$$ ? Need this ??
- CFocus embeddedDraw(ev, embeddedFacet);
-
- // Get the current clip shape
- tShape->CopyFrom(ev, tClippingShape);
-
- // Remove the drawn area from our clip shape
- tClippingShape->Subtract(ev, tShape);
-
- // Transform the shape before calling the embedded facet to draw
- Point offset;
- Rect tRect;
-
- this->GetBoundingBox(&tRect);
- offset.h = tRect.left;
- offset.v = tRect.top;
-
- // Convert shape's transform from parent frame to embedded frame
- ODTransform* tTransform = embeddedFacet->AcquireExternalTransform(ev, kODNULL);
- tShape->InverseTransform(ev, tTransform);
- ODReleaseObject(ev, tTransform);
-
- // Get the embedded facet's clip shape so we can subtract it from our working clip
- ODShape* tEmbeddedClipShape = embeddedFacet->AcquireClipShape(ev, kODNULL);
- tShape->CopyFrom(ev, tEmbeddedClipShape);
- ODReleaseObject(ev, tEmbeddedClipShape);
-
- // Give the shape the right transform
- tTransform = embeddedFacet->AcquireExternalTransform(ev, kODNULL);
- tShape->Transform(ev, tTransform);
- ODReleaseObject(ev, tTransform);
- }
- }
-
- // Release acquired geometry
- ODReleaseObject(ev, tShape);
- ODReleaseObject(ev, tClippingShape);
-
- // We don't want the rectangle to draw, so call CShape::Draw instead.
- CShape::DrawShape(ev, facet);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Embed
- //
- // Description: Embed the given part with the ( optional ) given frame. If no embedded
- // frame is passed in, this method will create one.
- //
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Embed( Environment* ev,
- ODPart* part,
- ODFrame* containingFrame,
- ODID embeddedFrameID)
- {
-
- ODDraft* draft = fDrawEditor->GetDraft(ev);
-
- // Frames are represented by proxies
- CEmbeddedFrameProxy* frameProxy = kODNULL;
-
- if (embeddedFrameID == kODNULL)
- {
- // Make a proxy
- frameProxy = new CEmbeddedFrameProxy();
- frameProxy->InitializeEmbeddedFrameProxy(ev,
- fDrawEditor,
- this,
- containingFrame,
- part);
- }
- else
- {
- // Make a proxy for it, using the frame passed in
- frameProxy = new CEmbeddedFrameProxy();
- frameProxy->InitializeEmbeddedFrameProxy(ev,
- fDrawEditor,
- this,
- embeddedFrameID,
- containingFrame);
-
- // Get the shape of the frame and set the size of the CEmbeddingShape
- // we should delay this until later. Causing frame to be loaded to early.
- // DCS $$$$$
- ODFrame* tFrame = frameProxy->GetFrame(ev);
-
- ODShape* tShape = tFrame->AcquireFrameShape(ev, kODNULL);
- ODRgnHandle tODRegion = tShape->GetQDRegion(ev);
- this->SetBoundingBox(ev, (*tODRegion)->rgnBBox);
-
- // Release acquired geometry
- ODReleaseObject(ev, tShape);
- }
-
- // Add to our list of frameProxies
- this->AddFrameProxy(frameProxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::SetFrozen
- //----------------------------------------------------------------------------------------
-
- ODBoolean CEmbeddingShape::SetFrozen(ODBoolean state)
- {
- return kODFalse;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Show
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Show(Environment* ev, ODBoolean show)
- {
- if (show)
- {
- if (!this->IsShown())
- {
- // Iterate over all the proxies and attach, if necessary
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- if (!frameProxy->IsAttached(ev))
- frameProxy->Attach(ev);
- }
- }
- }
- else
- // We are hiding
- {
- if (this->IsShown())
- {
- // Iterate over all the proxies and detach, if necessary
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- if (frameProxy->IsAttached(ev))
- frameProxy->Detach(ev);
- }
- }
- }
-
-
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Activate
- // An (de)activate, suspend, or resume event has occured. Change the highlight state of
- // corresponding facets' highlight state to reflect the change in active state.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Activate(Environment* ev, ODBoolean activating, ODFrame* frame)
- {
- ODFacet* tFacet = this->GetEmbeddedFacet(ev, frame);
-
- ODHighlight highlight;
- if ( this->IsSelected() && activating ) highlight = kODFullHighlight;
- else if ( this->IsSelected() && !activating ) highlight = kODDimHighlight;
- else highlight = kODNoHighlight;
-
- ::ChangeFacetHighlight(ev, tFacet, highlight);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Resize
- //------------------------------------------------------------------------------
- void CEmbeddingShape::Resize(Environment *ev, Rect& baseRect, Rect& resizeRect)
- {
- CRectangleShape::Resize(ev, baseRect, resizeRect);
-
- ODRect odResizeRect(fRect);
-
- // Iterate over FrameProxies and resize each of them.
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- frameProxy->ResizeFrame(ev, odResizeRect);
- }
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::GetEmbeddedFacet
- //------------------------------------------------------------------------------
-
- ODFacet* CEmbeddingShape::GetEmbeddedFacet(Environment *ev, ODFacet* containingFacet)
- {
- ODFacet* embeddedFacet = kODNULL;
-
- // Proxy Iterator
- COrdListIterator iter(fFrameProxies);
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- do
- {
- // Check all facets
- ODFrameFacetIterator* iter2 = frameProxy->GetFrame(ev)->CreateFacetIterator(ev);
- for (ODFacet* facet = iter2->First(ev); iter2->IsNotComplete(ev); facet = iter2->Next(ev))
- {
-
- if (facet->GetContainingFacet(ev)->GetFrame(ev) ==
- containingFacet->GetFrame(ev))
- {
- embeddedFacet = facet;
- }
- }
- frameProxy = (CEmbeddedFrameProxy*)iter.Next();
- } while (iter.IsNotComplete() && !embeddedFacet);
- return embeddedFacet;
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::GetEmbeddedFacet
- //------------------------------------------------------------------------------
-
- ODFacet* CEmbeddingShape::GetEmbeddedFacet(Environment* ev, ODFrame* containingFrame)
- {
- ODFacet* embeddedFacet = kODNULL;
-
- // Proxy Iterator
- COrdListIterator iter(fFrameProxies);
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- do
- {
- // Check all facets
- ODFrameFacetIterator* iter2 = frameProxy->GetFrame(ev)->CreateFacetIterator(ev);
- for (ODFacet* facet = iter2->First(ev); iter2->IsNotComplete(ev); facet = iter2->Next(ev))
- {
-
- if (facet->GetContainingFacet(ev)->GetFrame(ev) ==
- containingFrame)
- {
- embeddedFacet = facet;
- }
- }
- frameProxy = (CEmbeddedFrameProxy*)iter.Next();
- } while (iter.IsNotComplete() && !embeddedFacet);
- return embeddedFacet;
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::GetAnyFrame
- // Sometimes OpenDoc just wants a frame. So, this method will return the first
- // embedded frame ( in memory ) found for "this" shape. kODNULL is returned
- // if no frames are in memory.
- //------------------------------------------------------------------------------
-
- ODFrame* CEmbeddingShape::GetAnyFrame(Environment *ev)
- {
- ODFrame* embeddedFrame = kODNULL;
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- // Proxy Iterator
- COrdListIterator iter(fFrameProxies);
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- for (CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete();
- frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // If frameProxy's frame is loaded, return it
- if (frameProxy->IsFrameInMemory())
- {
- return frameProxy->GetFrame(ev);
- }
- }
-
- return kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::ContainsProxyForFrame
- //
- // This method should return kODTrue if the given frame is embedded within this
- // item of content.
- //
- // NOTE: Does not cause load of frame.
- //------------------------------------------------------------------------------
-
- ODBoolean CEmbeddingShape::ContainsProxyForFrame(Environment* ev, ODFrame* frame)
- {
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for (CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete();
- frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- if (frame->GetID(ev) == frameProxy->GetFrameID())
- return kODTrue;
- }
-
- // Did not find a match
- return kODFalse;
- }
-
-
- //------------------------------------------------------------------------------
- // CShape::SetInLimbo
- //
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::SetInLimbo(Environment* ev, ODBoolean isInLimbo)
- {
- // Notify all of our proxies of limbo status. See limbo discussion
- // in the programmers guide for more details.
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- frameProxy->SetInLimbo(ev, isInLimbo);
- }
- }
-
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::OffsetShape
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::OffsetShape(Environment* ev, ODCoordinate xDelta, ODCoordinate yDelta)
- {
- CRectangleShape::OffsetShape(ev, xDelta, yDelta);
-
- ODPoint offset(xDelta, yDelta);
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- // Iterate over all proxy frames and offset them
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- frameProxy->OffsetFrame(ev, offset);
- }
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Removed
- // This method is called to remove a frame from the document. If the commit flag is false
- // then the shape will merely be detached with the assumption that the shape will be later
- // re-added. If the commit flag is true, then the shape will PERMANENTLY be removed. That
- // is to say, the frame will be removed from the parts embedded frame list, the Remove
- // method will be called on the frame ( notifiying OD that the frame should be dismantled.
- //
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Removed(Environment* ev, ODBoolean commit)
- {
- CRectangleShape::Removed(ev, commit);
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // Remove the shape ( frame ) from the visual hierarchy
- if (frameProxy->IsAttached(ev))
- frameProxy->Detach(ev);
-
- if (commit)
- {
- frameProxy->RemoveAndPurge(ev);
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Added
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Added(Environment *ev)
- {
- CRectangleShape::Added(ev);
-
- // Add the shape ( frame ) to the document
- this->SetInLimbo(ev, kODFalse);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Open
- //
- // This method is called by the part when the user has selected "Open" for a selection.
- // This will probably be only overridden by the proxy derivatives of shape.
- //----------------------------------------------------------------------------------------
- void CEmbeddingShape::Open(Environment *ev, ODFrame* container)
- {
- // Use the embedded frame for the provided container
- ODFrame* tFrame = this->GetEmbeddedFacet(ev, container)->GetFrame(ev);
-
- // tell the part to open
- ODPart* tPart = tFrame ? tFrame->AcquirePart(ev) : kODNULL;
- if (tPart)
- {
- tPart->Open(ev, tFrame);
-
- ODReleaseObject(ev, tPart);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::DisplayFrameConnected
- //
- // This method is called by the part when a document is loaded and one of its display
- // frames has been internalized from storage and "connected" into the frame hierarchy.
- // When this happens, we must execute the below special case code to make sure that our
- // embedded content is re-internalized correctly.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::DisplayFrameConnected(Environment *ev, ODFrame* frame)
- {
- // SPECIAL CASE: In the case where a document was saved with embedded content AND then
- // dragged into a container which only clones the root part and does not use the root
- // frame for the document. In this case we must assume that any orphaned frame proxies
- // belong to the frame being added, and therefore attach the given frame to the orphaned
- // proxy frames. It is possible that there may have been multiple saved ( persistent )
- // display frames. That being the case, we will return as soon as we find 1 orphaned
- // proxy ( after having re-attached it to the passed in dispaly frame ). This way, if there
- // were multiple display frames saved, each one will get a proxy as it is internalized.
- // I can't guarantee correct restoration of ordering ( proxy to frame ), but that shouldn't
- // be important ( famous last words ).
-
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- if (frameProxy->IsOrphaned())
- {
- frameProxy->SetContainingFrame(ev, frame->GetID(ev));
- return;
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::DisplayFrameAdded
- //
- // This method is called by the part whenever a new display frame is added to the
- // container part. We must create a new embedded frame for this new container frame so
- // that this shape will be displayed correctly in that new frame.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::DisplayFrameAdded(Environment *ev, ODFrame* frame)
- {
- // Find the part that this shape is 'wrapping'
- ODPart* embeddedPart = kODNULL;
-
- if (fFrameProxies->Count()==0)
- {
- // Can we add a containing frame to a shape with no proxies?
- // DCS $$$$$
- DebugStr("\pCan't add frame to shape, there are no proxies.");
- }
-
- // Scan proxies. If we have an orphaned proxy, attach it to the given frame, otherwise
- // Try to access a part reference with which we can create a new proxy for the given
- // frame.
- COrdListIterator iter(fFrameProxies);
- CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- do
- {
- if (frameProxy->IsOrphaned())
- {
- // See special case comment in CEmbeddingShape::DisplayFrameConnected above.
- frameProxy->SetContainingFrame(ev, frame->GetID(ev));
- return;
- }
- else
- if (frameProxy->IsFrameInMemory())
- {
- embeddedPart = frameProxy->GetFrame(ev)->AcquirePart(ev);
- }
-
-
- frameProxy = (CEmbeddedFrameProxy*)iter.Next();
- } while (iter.IsNotComplete()&&!embeddedPart);
-
- if (embeddedPart)
- {
- // Make a proxy for the frame
- frameProxy = new CEmbeddedFrameProxy();
- frameProxy->InitializeEmbeddedFrameProxy(ev,
- fDrawEditor,
- this,
- frame,
- embeddedPart);
-
- // Add to our list of frameProxies
- this->AddFrameProxy(frameProxy);
-
- // Release acquired part
- ODReleaseObject(ev, embeddedPart);
- }
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::DisplayFrameRemoved
- //
- // This method is called by the part when a display frame is removed.
- // This allows us to add a facet to the embedded frame wrapped by this shape.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::DisplayFrameRemoved(Environment *ev, ODFrame* frame)
- {
- // I am assuming that there will be only one frame proxy for a given frame
- CEmbeddedFrameProxy* tProxy = kODNULL;
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // ----- Remove the frame & proxy -----
- ODFrame* proxyContainer = frameProxy->AcquireContainingFrame(ev);
- if (proxyContainer==frame)
- {
- tProxy = frameProxy;
- ODFrame* embeddedFrame = tProxy->GetFrame(ev);
-
- // Remove abandoned frame proxy from our list
- // Shouldn't call GetFrame after this.
- tProxy->Detach(ev);
-
- /// ODFrame::Remove calls release
- tProxy->RemoveAndPurge(ev);
- }
-
- // Release acquired container frame
- ODReleaseObject(ev, proxyContainer);
- }
- // Remove proxy from this shape's list then delete it.
- fFrameProxies->Remove(tProxy);
- delete tProxy;
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::DisplayFrameClosed
- //
- // This method is called by the part when a display frame is removed.
- // This allows us to add a facet to the embedded frame wrapped by this shape.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::DisplayFrameClosed(Environment *ev, ODFrame* frame)
- {
- // I am assuming that there will be only one frame proxy for a given frame
- CEmbeddedFrameProxy* tProxy = kODNULL;
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // ----- Remove the frame & proxy -----
- ODFrame* proxyContainer = frameProxy->AcquireContainingFrame(ev);
- if (proxyContainer==frame)
- {
- tProxy = frameProxy;
- ODFrame* embeddedFrame = tProxy->GetFrame(ev);
-
- // Remove abandoned frame proxy from our list
- // Don't call GetFrame on the proxy after this.
- tProxy->Detach(ev);
-
- // Tell OD to remove the frame, clear the proxy's structure.
- tProxy->CloseAndPurge(ev);
- }
-
- // Release acquired container frame
- ODReleaseObject(ev, proxyContainer);
- }
- // Remove proxy from this shape's list, then delete it
- // Must remove & delete outside of iteration to avoid confusing iterator
- fFrameProxies->Remove(tProxy);
- delete tProxy;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::Dragging
- //
- // This method is called by the part when a the user is or was dragging this shape.
- // Notify the embedded frame of the state of dragging.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::Dragging(Environment *ev, ODBoolean dragging)
- {
- // Notify all of our proxies.
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- ODFrame* frame = frameProxy->GetFrame(ev);
- frame->SetDragging(ev, dragging);
- }
- }
-
-
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::FacetAdded
- //
- // This method is called by the part when a new containing facet is added.
- // This allows us to add a facet to the embedded frame wrapped by this shape.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::FacetAdded(Environment *ev, ODFacet* facet)
- {
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // ----- Add facets to the frame being proxy, IF the frame is in memory -----
-
- if (frameProxy->IsFrameInMemory())
- {
- ODFrame* facetContainer = facet->GetFrame(ev);
- ODFrame* proxyContainer = frameProxy->AcquireContainingFrame(ev);
- if (facetContainer==proxyContainer)
- {
- frameProxy->CreateFacetsForContainer(ev, facet);
- }
-
- // Set the hilight state of the embedded facet
- ODFacet* tFacet = GetEmbeddedFacet(ev, facet);
-
- ODHighlight highlight;
- ODBoolean active = facet->GetWindow(ev)->IsActive(ev);
-
- if ( this->IsSelected() && active ) highlight = kODFullHighlight;
- else if ( this->IsSelected() && !active ) highlight = kODDimHighlight;
- else highlight = kODNoHighlight;
-
- tFacet->SetSelected(ev, this->IsSelected());
- ::ChangeFacetHighlight(ev, tFacet, highlight);
-
- // Release acquired container frame
- ODReleaseObject(ev, proxyContainer);
- }
- }
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CEmbeddingShape::FacetRemoved
- //
- // This method is called by the part when a containing facet is removed.
- // This allows us to remove the facet contained by the facet that is removed.
- //----------------------------------------------------------------------------------------
-
- void CEmbeddingShape::FacetRemoved(Environment *ev, ODFacet* facet)
- {
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- // ----- Remove the frame & proxy -----
- ODFrame* facetContainer = facet->GetFrame(ev);
- ODFrame* proxyContainer = frameProxy->AcquireContainingFrame(ev);
- if (facetContainer==proxyContainer)
- {
- frameProxy->RemoveFacetsForContainer(ev, facet);
- }
-
- // Release acquired container frame
- ODReleaseObject(ev, proxyContainer);
- }
- }
-
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Read
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is the beginning of a shape.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::Read(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo)
- {
- CEmbeddingShape::Read(ev, view->GetStorageUnit(ev), cloneInfo);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Read
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is the beginning of a shape.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo)
- {
- CRectangleShape::Read(ev, storage, cloneInfo);
-
- /// Read the number of proxies
- ODULong proxyCount;
- StorageUnitGetValue(storage, ev, sizeof(ODULong), &proxyCount);
-
- // Read in the proxies
- for (ODULong index = 0; index < proxyCount; index++)
- {
- // Make a proxy
- CEmbeddedFrameProxy* frameProxy = new CEmbeddedFrameProxy();
- frameProxy->InitializeEmbeddedFrameProxy(ev, fDrawEditor, this);
-
- if (frameProxy->Read(ev, storage, cloneInfo))
- {
- this->AddFrameProxy(frameProxy);
- }
- else
- THROW(kODErrInvalidStorageUnitRef);
- }
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Write
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is a good place to write out a shape.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::Write(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo)
- {
- this->Write(ev, view->GetStorageUnit(ev), cloneInfo);
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Write
- // We assume that the storage unit is focused to a property and value and
- // that the current offset is a good place to write out a shape.
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::Write(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo)
- {
- CRectangleShape::Write(ev, storage, cloneInfo);
-
- /// Write the number of proxies
- ODULong proxyCount = fFrameProxies->Count();
- StorageUnitSetValue(storage, ev, sizeof(ODULong), &proxyCount);
-
- // Write out the proxies contained by the scope ( source of copy ) frame
- // specified in the cloneInfo
-
-
- // Iterate over all the proxies to locate the one belonging to the given parent
- COrdListIterator iter(fFrameProxies);
- for ( CEmbeddedFrameProxy* frameProxy = (CEmbeddedFrameProxy*)iter.First();
- iter.IsNotComplete(); frameProxy = (CEmbeddedFrameProxy*)iter.Next())
- {
- ODFrame* containingFrame = frameProxy->AcquireContainingFrame(ev);
-
- // If we are cloning, then write only in the case where there is
- // no scope frame or the proxy falls within the scope frame.
- // Write if we are not doing a clone, as well.
- if (cloneInfo && cloneInfo->fScopeFrame==kODNULL)
- frameProxy->Write(ev, storage, cloneInfo);
- else
- if (cloneInfo && containingFrame==cloneInfo->fScopeFrame)
- frameProxy->Write(ev, storage, cloneInfo);
- else
- if (cloneInfo==kODNULL)
- frameProxy->Write(ev, storage, cloneInfo);
-
- // Release acquired frame
- ODReleaseObject(ev, containingFrame);
- }
- }
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::Publish
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::Publish(Environment* ev, CPublishLink* link)
- {
- CShape::Publish (ev, link);
-
- if (fPublishLinks->Count() == 1)
- this->ChangeLinkStatus(ev, kODInLinkSource);
-
- }
-
-
- //------------------------------------------------------------------------------
- // CEmbeddingShape::ChangeLinkStatus
- //------------------------------------------------------------------------------
-
- void CEmbeddingShape::ChangeLinkStatus(Environment* ev, ODLinkStatus linkStatus)
- {
-
- // This is the way we've been doing it in ODFDrawLink, but ask *
- // if it's really necessary to do this to each frame. Does each frame as its
- // status is changed, then call the same part's LinkStatusChanged *again*?
-
- COrdListIterator iter(fFrameProxies);
- for (CEmbeddedFrameProxy* proxy = (CEmbeddedFrameProxy*)iter.First(); iter.IsNotComplete(); proxy = (CEmbeddedFrameProxy*)iter.Next())
- proxy->GetFrame(ev)->ChangeLinkStatus(ev, linkStatus);
- }
-
- #pragma segment Main
- void CEmbeddingShape::Subscribe(Environment* ev, CSubscribeLink* link)
- {
- CRectangleShape::Subscribe(ev, link);
-
- this->ChangeLinkStatus(ev, kODInLinkDestination);
- }
-
- #pragma segment Main
- void CEmbeddingShape::Unpublish(Environment* ev, CPublishLink* link)
- {
- CShape::Unpublish (ev, link);
-
- if (fPublishLinks->Count() == 0)
- this->ChangeLinkStatus(ev, kODNotInLink);
-
- }
-
-
- #pragma segment Main
- void CEmbeddingShape::Unsubscribe(Environment* ev)
- {
- CShape::Unsubscribe(ev);
-
- if (fPublishLinks->Count() != 0)
- this->ChangeLinkStatus(ev, kODInLinkSource);
- else
- this->ChangeLinkStatus(ev, kODNotInLink);
-
- }
-
-
-
-
-
-
-